/**
   * cookie 操作集合
   * @type {{getCookie: getCookie, setCookie: setCookie, setSecondsCookie: setSecondsCookie, clearCookie: clearCookie}}
   */
let COOKIE = {
    /**
     * 读取cookie
     * @param c_name
     * @returns {*}
     */
    getCookie: function getCookie(c_name) {
        if (document.cookie.length > 0) {
            let c_start = document.cookie.indexOf(c_name + '=')
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1
                let c_end = document.cookie.indexOf(';', c_start)
                if (c_end == -1) {
                    c_end = document.cookie.length
                }
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return ''
    },

    /**
     * 设置cookie
     * @param c_name
     * @param value
     * @param expiredays
     */
    setCookie: function setCookie(c_name, value, expiredays) {
        let expDate = new Date()
        expDate.setDate(expDate.getDate() + expiredays)
        document.cookie = c_name + '=' + escape(value) + ((expiredays == null) ? '' : ';expires=' + expDate.toGMTString()) + ';path=/'
    },

    /**
     *  设置cookie
     * @param c_name
     * @param value
     * @param seconds
     */
    setSecondsCookie: function setSecondsCookie(c_name, value, seconds) {
        let expDate = new Date()
        expDate.setTime(expDate.getTime() + seconds * 1000)
        document.cookie = c_name + '=' + escape(value) + ((seconds == null) ? '' : ';expires=' + expDate.toGMTString()) + ';path=/'
    },

    /**
     *  删除cookie
     * @param name
     */
    clearCookie: function clearCookie(name) {
        setCookie(name, '', -1)
    }
}

export default COOKIE